package thread;

public class theardDemo8 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("线程在工作");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
            System.out.println("工作结束");
        });
        t.start();
        Thread.sleep(4000);
        System.out.println("结束线程工作");
        t.interrupt();//类似改变标志的布尔值

    }
}
